package com.example.library;

import android.content.Context;
import android.provider.Settings;
import android.view.KeyEvent;
import android.widget.EditText;
import android.widget.TextView;

/**
 * Created by gaoyeping on 2017/5/19.
 */

public class XPTextUtils {
    private static EditText editText;
    private static Context context;   

    public XPTextUtils(EditText editText, Context context) {
        this.editText = editText;
        this.context = context;
    }

    public static void setExpressionEdit(String text) {
        if (text.equals("[del]")) {
            editText.dispatchKeyEvent(new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_DEL));
        } else {
            editText.append(SpanStringUtils.getExpressionContent(context, (int) editText.getTextSize(), text));
        }
    }

    public void setExpressionText(Context context, TextView textView, String text) {
        textView.setText(SpanStringUtils.getExpressionContent(context, (int) textView.getTextSize(), text));
    }

    public void recycle() {
        editText = null;
        context = null;
        System.gc();
    }
}
